package com.wyiot.pet.model.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.wyiot.core.enums.OrderStatusEnum;
import com.wyiot.core.enums.TransportationEnum;
import lombok.Data;
import org.apache.ibatis.type.Alias;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.Random;

/**
 * 订单实体类
 *
 * @author yly
 * @date 2022年03月24日
 */
@Data
@TableName("pet_order")
@Alias("order")
public class OrderDO {
    @TableId(type = IdType.AUTO)
    /** 订单id*/
    private Long orderId;
    /**
     * 订单编号
     */
    private String orderNumber;
    /**
     * 寄件人id
     */
    private Long userId;
    /**
     * 寄件人姓名
     */
    private String userName;
    /**
     * 寄件人手机号
     */
    private String userPhone;
    /**
     * 寄件地址城市
     */
    private String sendAddressCity;
    /**
     * 寄件地址详情
     */
    private String sendAddressDetail;
    /**
     * 收件人姓名
     */
    private String receiverName;
    /**
     * 收件人电话
     */
    private String receiverPhone;
    /**
     * 收件人地址城市
     */
    private String receiverAddressCity;
    /**
     * 收件人地址详情
     */
    private String receiverAddressDetail;
    /**
     * 运输方式
     */
    private TransportationEnum orderTransportation;
    /**
     * 订单状态
     */
    private OrderStatusEnum orderState;
    /**
     * 订单取件人员Id
     */
    private Long orderTakeMan;
    /**
     * 订单派件人员Id
     */
    private Long orderSendMan;

    /**
     * 支付流水号
     */
    private String orderSerialNumber;
    /**
     * 订单是否支付
     */
    private boolean orderIspay;
    /**
     *订单金额
     */
    private int orderAmount;
    /**
     * 订单揽件员取件码
     */
    private Integer takeCode;
    /**
     * 订单用户取件码
     */
    private Integer userTakeCode;
    /**
     * 订单创建时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    /**
     * 开始上门取件时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date orderDoorBeginTime;
    /**
     * 结束上门时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date orderDoorEndTime;
    /**
     * 预计到达时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date expectedDeliveryTime;
    /**
     * 订单完成时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date orderEndTime;
    /**
     * 取消时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date orderCancelTime;
    /**
     * 申请退款时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date applyRefundTime;
    /**
     * 退款时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date refundTime;
    /**
     * 支付时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date payTime;
    /**
     * 物流信息(车号)
     */
    private String carNumber;
    /**
     * 始发站
     */
    private String departureStation;
    /**
     * 终点站
     */
    private String destination;

    public void genTakeCode(){
        String result = "";
        Random random = new Random();
        for (int i = 0; i < 4; i++) {
            result += random.nextInt(10);
        }
        this.takeCode = Integer.valueOf(result);
    }

    public void genSerialNumber(){
        String DD = "ZF";
        String time = String.valueOf(new Date().getTime());
        String result = "";
        Random random = new Random();
        for (int i = 0; i < 5; i++) {
            result += random.nextInt(10);
        }
        this.orderSerialNumber = DD + time + result;
    }
    public void genOrderNumber() {
        String DD = "KY";
        String time = String.valueOf(new Date().getTime());
        String result = "";
        Random random = new Random();
        for (int i = 0; i < 5; i++) {
            result += random.nextInt(10);
        }
        this.orderNumber = DD + time + result;
    }

}
